package com.example.network

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.network.databinding.ActivityMainBinding
import com.example.network.http.HttpActivity
import com.example.network.parse.json.JsonActivity
import com.example.network.parse.xml.XmlActivity
import com.example.network.retrofit.RetrofitActivity
import com.example.network.socket.WebSocketActivity
import com.example.network.util.launchActivity

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityMainBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        initButtons()

//        launchActivity<RetrofitActivity>()
        launchActivity<WebSocketActivity>()
    }

    private fun initButtons() {
        binding.http.setOnClickListener {
            launchActivity<HttpActivity>()
        }
        binding.okhttp.setOnClickListener {
            launchActivity<OkhttpActivity>()
        }
        binding.jsonBtn.setOnClickListener {
            launchActivity<JsonActivity>()
        }
        binding.xmlBtn.setOnClickListener {
            launchActivity<XmlActivity>()
        }
        binding.retrofitBtn.setOnClickListener {
            launchActivity<RetrofitActivity>()
        }
        binding.websocketBtn.setOnClickListener {
            launchActivity<WebSocketActivity>()
        }
    }
}